package com.bcx.service.impl;

import com.bcx.mapper.DetailMapper;
import com.bcx.pojo.Detail;
import com.bcx.pojo.DetailExample;
import com.bcx.service.DetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DetailServiceImpl implements DetailService {
    @Resource
    DetailMapper detailMapper;
    @Override
    public PageInfo<Detail> selectAll(Integer sortid, Integer pageNum) {
        PageHelper.startPage(pageNum,2);
        List<Detail> detailList;
        DetailExample example=new DetailExample();
        if (sortid!=0){
            DetailExample.Criteria criteria=example.createCriteria();
            criteria.andSortidEqualTo(sortid);
            detailList=detailMapper.selectByExample(example);
        }else{
            detailList=detailMapper.selectByExample(null);
        }
        PageInfo<Detail> pageInfo=new PageInfo<>(detailList);
        return pageInfo;
    }

    @Override
    public Integer insert(Detail detail) {
        return detailMapper.insert(detail);
    }

    @Override
    public Integer delete(Integer id) {
        return detailMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Detail getById(Integer id) {
        return detailMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer update(Detail detail) {
        return detailMapper.updateByPrimaryKeySelective(detail);
    }
}
